package cn.edu.nju.software.gui;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cn.edu.nju.software.net.CourseBean;
import cn.edu.nju.software.net.StudentBean;

public class AddCoursesPanel extends JPanel{
		
	
		
		JLabel id;
		JTextField idValue;
		JLabel name;
		JTextField nameValue;
		JLabel institute ;
		JTextField instituteValue;
		JLabel teacher ;
		JTextField teacherValue;
		JLabel grade;
		JTextField gradeValue;
		JLabel number;
		JTextField numberValue;
		JLabel place;
		JTextField placeValue;
		JLabel shared;
		JTextField sharedValue;


		
		
		
	
		public AddCoursesPanel(){
		    setLayout(new BorderLayout(1,16));
			id = new JLabel("id");
			idValue = new JTextField("");
			add(id);
			add(idValue);
			
			name = new JLabel("name");
			nameValue = new JTextField("");
			add(name);
		    add(nameValue);
			
			institute = new JLabel("institute");
			instituteValue = new JTextField("");
			add(institute);
			add(instituteValue);
			
			teacher = new JLabel("teacher");
			teacherValue = new JTextField("");
			add(teacher);
			add(teacherValue);
			
			grade = new JLabel("grade");
			gradeValue = new JTextField("");
			add(grade);
			add(gradeValue);
			
			number = new JLabel("number");
			numberValue = new JTextField("");
			add(number);
			add(numberValue);
			
			
			place = new JLabel("place");
			placeValue = new JTextField("");
			add(place);
			add(placeValue);
			
			shared = new JLabel("shared");
			sharedValue = new JTextField("");
			add(shared);
			add(sharedValue);
			
		}
		
		public boolean checkInput(){//ensure there is no empty element
			if( idValue.getText().equals("")||
			    nameValue.getText().equals("")||
				instituteValue.getText().equals("")||
				teacherValue.getText().equals("")||
			    gradeValue.getText().equals("")||
				numberValue.getText().equals("")||
				placeValue.getText().equals("")||
				sharedValue.getText().equals("")
					)
				return false;
			else
				return true;
		}
		
		
		public boolean checkShared(){
			if(sharedValue.getText().equals("Yes")||sharedValue.getText().equals("No"))
				return true;
			else
				return false;
		}
		
		
		
		public CourseBean getCourse(){
			
			return new CourseBean(
					idValue.getText(),
				    nameValue.getText(),
					instituteValue.getText(),
					teacherValue.getText(),
				    Integer.parseInt(gradeValue.getText()),
				    Integer.parseInt(numberValue.getText()),
					placeValue.getText(),
					sharedValue.getText().equals("Yes"));
					}
		
		public void clear(){
			idValue.setText("");//clear the textFields
			nameValue.setText("");
			instituteValue.setText("");
			teacherValue.setText("");
			gradeValue.setText("");
			numberValue.setText("");
			placeValue.setText("");
			sharedValue.setText("No");
		}
}
